@echo off
@echo This batch program will convert the Development Version of Maxsi Distribution  
@echo into a Release Version. To use, please enter the version of Maxsi Distribution
@echo you are releasing. Please use the format: Major.Minor                               

rem Remember to have 7zxx.exe in a system search path or along this batch script.
rem 7-zip is released under the GNU Lesser General Public license. This license
rem should have been provided with Maxsi Distribution. If not see www.fsf.org
rem For the source code of 7-zip please see http://www.7-zip.org/
rem (xx is the bit-depth, 32 for 32-bit Windows, 64 for 32-bit Windows).

rem Remember to have vspc.exe in a system search path or along this batch script.
rem vspc is released under the GNU General Public license. This license
rem should have been provided with Maxsi Distribution. If not see www.fsf.org
rem For the source code of vspc please see http://sourceforge.net/projects/vspc/


rem To work correctly, you need to set up these paths correctly

set /P MDVERSION=Please Enter The Version: 
set MDReleaseName=MaxsiDistribution-%MDVERSION%
set Root=..\..\
set InputMaxsiRoot=..\
set OutputDir=%Root%\%MDReleaseName%
set MDBIN=%OutputDir%\Maxsi Distribution
set MDSRC=%OutputDir%\Maxsi Distribution SRC
set MDSDK=%OutputDir%\Maxsi Distribution SDK\Source SDK
set MDSVR=%OutputDir%\Maxsi Distribution Server
set MDRLS=%Root%\Maxsi Distribution Release
set MDREADME=%OutputDir%\Maxsi Distribution ReadMe
set MDTOOLS=%OutputDir%\Maxsi Distribution Tools
set INPUTBIN=%MDSRC%\bin32
set INPUTSRC=%InputMaxsiRoot%\Maxsi Distribution SRC
set INPUTSDK=%OutputDir%\Maxsi Distribution SRC\MaxsiDistributionSDK
set INPUTSVR=%InputMaxsiRoot%\Maxsi Distribution Server
set INPUTREADME=%InputMaxsiRoot%\Maxsi Distribution ReadMe
set INPUTTOOLS=%InputMaxsiRoot%\Maxsi Distribution Tools
set DEBUGVSCONVERSION=0

if not exist "%INPUTSRC%\MaxsiEnvironment.bat" goto InvalidMDSRC
goto ValidMDSRC


:InvalidMDSRC
echo %INPUTSRC% does not point to a valid MD SRC/ folder (MaxsiEnvironment.bat is missing).
pause
exit /B

:ValidMDSRC

CALL "%INPUTSRC%\MaxsiEnvironment.bat"

rmdir /S /Q "%OutputDir%\"
mkdir "%OutputDir%"
mkdir "%MDBIN%"
mkdir "%MDSRC%"
mkdir "%MDSDK%"
mkdir "%MDSVR%"
mkdir "%MDREADME%"
mkdir "%MDTOOLS%"


xcopy "%INPUTSRC%" "%MDSRC%" /E /C
rename "%MDSRC%\bin32\zdll.lib" "zdll.lib.tmp"
del "%MDSRC%\*.ncb" /S
del "%MDSRC%\*.exp" /S
del "%MDSRC%\*.idb" /S
del "%MDSRC%\*.ilk" /S
del "%MDSRC%\*.lib" /S
del "%MDSRC%\*.log" /S
del "%MDSRC%\*BuildLog.htm" /S
del "%MDSRC%\*.obj" /S
del "%MDSRC%\*.o" /S
del "%MDSRC%\*.intermediate.manifest" /S
del "%MDSRC%\*.embed.manifest" /S
del "%MDSRC%\*.dep" /S
del "%MDSRC%\*.idb" /S
del "%MDSRC%\*vc80.pdb" /S
del "%MDSRC%\*vc90.pdb" /S
del "%MDSRC%\*.suo" /S
del "%MDSRC%\*.user" /S
del "%MDSRC%\*.res" /S
del "%MDSRC%\*.mdmp" /S
del "%MDSRC%\MaxsiRickRoll.*" /S
del "%MDSRC%\MaxsiSkyNet.*" /S
rmdir /S /Q "%MDSRC%\MaxsiExtractor_old\"
rmdir /S /Q "%MDSRC%\MaxsiRickRoll\"
rmdir /S /Q "%MDSRC%\Maxsi SkyNet (Home Edition)\"

if %DEBUGVSCONVERSION%==1 pause

set TMPPROJECT=MaxsiDistribution
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiDistributionProtocol (Exe)
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiDistributionSDK
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiEngine
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiExtractor
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiFeedback
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiImaginationLand
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiInstaller
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiIO
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiPlay
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiReleaseCMD
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"
set TMPPROJECT=MaxsiMapSync
copy "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSLOCALDEV%.vcproj" "%MDSRC%\%TMPPROJECT%\%TMPPROJECT%-%VSPORTTO%.vcproj"

if %DEBUGVSCONVERSION%==0 vspc VS%VSLOCALDEV% VS%VSPORTTO% "%MDSRC%\MaxsiDistribution-%VSPORTTO%.sln" --quiet
if %DEBUGVSCONVERSION%==1 vspc VS%VSLOCALDEV% VS%VSPORTTO% "%MDSRC%\MaxsiDistribution-%VSPORTTO%.sln"
if %DEBUGVSCONVERSION%==1 pause
if %DEBUGVSCONVERSION%==0 vspc VS%VSLOCALDEV% VS%VSPORTTO% "%MDSRC%\MaxsiTechnology-%VSPORTTO%.sln" --quiet
if %DEBUGVSCONVERSION%==1 vspc VS%VSLOCALDEV% VS%VSPORTTO% "%MDSRC%\MaxsiTechnology-%VSPORTTO%.sln"
if %DEBUGVSCONVERSION%==1 pause

del "%MDSRC%\*.cvttmp" /S

rename "%MDSRC%\bin32\zdll.lib.tmp" "zdll.lib"


mkdir "%MDBIN%\bin32"
mkdir "%MDBIN%\Sortie"
mkdir "%MDBIN%\Sortie\bin32"
xcopy "%INPUTBIN%" "%MDBIN%\%MDBuild%\bin32" /E /C
xcopy "%INPUTBIN%\MaxsiDistributionProtocol*" "%MDBIN%\bin32\MaxsiDistributionProtocol*" /C
del "%MDBIN%\*.pdb" /S
del "%MDBIN%\*.lib" /S


mkdir "%MDSVR%\addons"
mkdir "%MDSVR%\scripts"
mkdir "%MDSVR%\Licenses"
copy "%INPUTSVR%\index.php" "%MDSVR%\index.php"
copy "%INPUTSVR%\Licenses\MD-License.txt" "%MDSVR%\Licenses\MD-License.txt"
xcopy "%INPUTSVR%\addons" "%MDSVR%\addons" /C /E
del "%MDSVR%\addons\shared\database_password.php"


xcopy "%INPUTSDK%\MaxsiDistribution*" "%MDSDK%\MaxsiDistribution*" /C
del "%MDSDK%\*.user" /S
del "%MDSDK%\*.vcproj" /S


xcopy "%INPUTREADME%" "%MDREADME%" /E /C


xcopy "%INPUTTOOLS%" "%MDTOOLS%" /C /E


rmdir /S /Q "%MDRLS%\"
mkdir "%MDRLS%"
mkdir "%MDRLS%\Maxsi Distribution"
xcopy "%MDBIN%" "%MDRLS%\Maxsi Distribution" /E /C
REM "%MDRoot%\%MDBuild%\dev32\MaxsiReleaseCMD.exe" "Release Maxsi Distribution.mis"


rmdir /S /Q "%MDRLS%\"
mkdir "%MDRLS%"
mkdir "%MDRLS%\Maxsi Distribution SDK"
xcopy "%MDSDK%" "%MDRLS%\Maxsi Distribution SDK" /E /C
rem "%MDRoot%\%MDBuild%\dev32\MaxsiReleaseCMD.exe" "Release Maxsi Distribution SDK.mis"


rmdir /S /Q "%MDRLS%\"
mkdir "%MDRLS%"
mkdir "%MDRLS%\Maxsi Distribution Server"
xcopy "%MDSVR%" "%MDRLS%\Maxsi Distribution Server" /E /C
rem "%MDRoot%\%MDBuild%\dev32\MaxsiReleaseCMD.exe" "Release Maxsi Distribution Server.mis"


rmdir /S /Q "%MDRLS%\"
mkdir "%MDRLS%"
mkdir "%MDRLS%\Maxsi Distribution SRC"
xcopy "%MDSRC%" "%MDRLS%\Maxsi Distribution SRC" /E /C
rem "%MDRoot%\%MDBuild%\dev32\MaxsiReleaseCMD.exe" "Release Maxsi Distribution Source Code.mis"



rmdir /S /Q "%MDRLS%\"

del "%OutputDir%.zip"
7z%MDPSIZE%.exe a -tzip "%OutputDir%.zip" "%OutputDir%"

@echo Created Maxsi Distribution Release '%MDReleaseName%'
pause